//
//  WithdrawFooterView.swift
//  cxd4iphone
//
//  Created by hexy on 11/26/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let backgroundColor: UIColor   = xx_colorWithHex(hexValue: 0xededed)
}

class WithdrawView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        makeUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    var withdrawViewModel: WithDrawViewModel? {
        
        didSet {
            
            
        }
    }
    private func makeUI() {
        
        let topView = UIView(bgColor: UIColor.whiteColor())
        
        self.addSubview(topView)
        topView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self).offset(xx_height(20))
            make.left.right.equalTo(self)
            make.height.equalTo(xx_height(75))
        }
        
//        let topWrap = UIView(bgColor: xx_randomColor())
        let topWrap = UIView()
        
        topView.addSubview(topWrap)
        topWrap.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(UIEdgeInsetsMake(15, 15, -15, -15))
        }
        
        topWrap.addSubview(bankLogo)
        bankLogo.snp_makeConstraints { (make) -> Void in
            
            make.top.left.bottom.equalTo(topWrap)
            make.width.equalTo(50)
        }
        
        topWrap.addSubview(titleLabel)
        titleLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(bankLogo.snp_right)
            make.top.equalTo(topWrap)
        }
        
        topWrap.addSubview(detailLabel)
        detailLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(titleLabel.snp_bottom).offset(xx_height(5))
            make.left.equalTo(titleLabel)
        }
        
//        let bottomView = UIView(bgColor: xx_randomColor())
        let bottomView = UIView()
        
        self.addSubview(bottomView)
        bottomView.snp_makeConstraints { (make) -> Void in
            
            make.left.bottom.right.equalTo(self)
            make.height.equalTo(xx_height(80))
        }
        
        bottomView.addSubview(nextBtn)
        nextBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(bottomView).offset(15)
            make.right.equalTo(bottomView).offset(-15)
            make.centerY.equalTo(bottomView)
            make.height.equalTo(xx_height(40))
        }
        
//        let midView = UIView(bgColor: xx_randomColor())
        let midView = UIView()
        
        self.addSubview(midView)
        midView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(topView.snp_bottom)
            make.bottom.equalTo(bottomView.snp_top)
            make.left.right.equalTo(self)
        }
        
//        let midWrap = UIView(bgColor: xx_randomColor())
        let midWrap = UIView()
        
        midView.addSubview(midWrap)
        midWrap.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(UIEdgeInsetsMake(xx_height(10), 15, xx_height(-10), -15))
        }
        
        let tipLabel = UILabel(title: "诚信贷账户可用余额 (元)", fontColor: Define.moreLightFontColor, bgColor: nil, fontSize: 14, maxWrapWidth: 0)
        
        midWrap.addSubview(tipLabel)
        tipLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.left.equalTo(midWrap)
        }
        
        midWrap.addSubview(balanceLabel)
        balanceLabel.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(midWrap)
            make.centerY.equalTo(tipLabel)
        }
        
        midWrap.addSubview(textField)
        textField.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(tipLabel.snp_bottom).offset(xx_height(15))
            make.left.right.equalTo(midWrap)
            make.height.equalTo(xx_height(40))
        }
        
        
        let withdrawWayLabel = UILabel(title: "提现方式", fontSize: 12)
        
        midWrap.addSubview(withdrawWayLabel)
        withdrawWayLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(textField.snp_bottom).offset(xx_height(40))
            make.left.equalTo(midWrap)
        }
        
        midWrap.addSubview(t0withdrawBtn)
        t0withdrawBtn.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(midWrap)
            make.centerY.equalTo(withdrawWayLabel)
        }
        
        midWrap.addSubview(t1withdrawBtn)
        t1withdrawBtn.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(t0withdrawBtn.snp_left).offset(xx_width(-20))
            make.centerY.equalTo(withdrawWayLabel)
        }
        
        
        let withdradFeeLabel = UILabel(title: "提现费用 (元)", fontSize: 12)
        
        midWrap.addSubview(withdradFeeLabel)
        withdradFeeLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(withdrawWayLabel.snp_bottom).offset(xx_height(15))
            make.left.equalTo(midWrap)
        }
        
        midWrap.addSubview(numWithdradFeeLabel)
        numWithdradFeeLabel.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(midWrap)
            make.centerY.equalTo(withdradFeeLabel)
        }
    
        let realWithdradLabel = UILabel(title: "实际提现 (元)", fontSize: 12)
        
        midWrap.addSubview(realWithdradLabel)
        realWithdradLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(withdradFeeLabel.snp_bottom).offset(xx_height(15))
            make.left.equalTo(midWrap)
        }
        
        midWrap.addSubview(realNumWithdradLabel)
        realNumWithdradLabel.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(midWrap)
            make.centerY.equalTo(realWithdradLabel)
        }
        
        midWrap.addSubview(withdrawExplainBtn)
        withdrawExplainBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(realNumWithdradLabel.snp_bottom).offset(xx_height(15))
            make.right.equalTo(midWrap)
        }
        

    }
    
    lazy var bankLogo: UIButton = {
        
        let btn = UIButton(bgColor: xx_randomColor())
        btn.userInteractionEnabled = false
        return btn
    }()
    
    lazy var titleLabel = UILabel(num: "中国工商银行", fontSize: 15)
    lazy var detailLabel = UILabel(title: "尾号0000", fontColor: Define.moreLightFontColor, bgColor: nil, fontSize: 12, maxWrapWidth: 0)
    
    lazy var balanceLabel = UILabel(title: "0.00", fontColor: Define.redColor, bgColor: nil, fontSize: 18, maxWrapWidth: 0)
    lazy var textField = UITextField(placeholder: "请输入提现金额 (元)", textAlignment: .Left, keyboardType: .NumbersAndPunctuation)
    lazy var nextBtn = UIButton(title: "下一步", titleColor: UIColor.whiteColor(), titleSize: 18, bgColor: Define.redColor)
    
    lazy var t0withdrawBtn: UIButton = {
        
        let btn = UIButton(title: " 实时提现", normalImage: UIImage(named: "withdraw_normal")!, selectImage: UIImage(named: "withdraw_selected")!)
        
        return btn
    }()
    
    lazy var t1withdrawBtn: UIButton = {
        
        let btn = UIButton(title: " T+1提现", normalImage: UIImage(named: "withdraw_normal")!, selectImage: UIImage(named: "withdraw_selected")!)
        btn.selected = true
        return btn
    }()
    
    lazy var withdrawExplainBtn: UIButton = {
        
        let btn = UIButton(title: "提现说明", titleColor: Define.redColor, titleSize: 12, bgColor: UIColor.clearColor(), normalImage: UIImage(named: "withdraw_explain"))
        return btn
    }()

    
    lazy var numWithdradFeeLabel = UILabel(num: "0.00", fontSize: 14)
    lazy var realNumWithdradLabel = UILabel(num: "123.00", fontSize: 14)

    
    
    
}
